//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<IFileSystem.h>
///	@path	~/src/database/store/
///	@date	2007/11/23
///	@desc	File system interface.

#pragma once

#include "xeres.h"

#include "object/IObject.h"

#include "database/database.h"

struct IStream;

namespace xeres {

	// forward declaration
	class IFile;
	class IData;

	/*!
		\class	IFileSystem
		\brief	File system interface.
	*/
	class IFileSystem : public IObject
	{
	public:

		/// \ctor
		IFileSystem( void );

		/// \dtor
		virtual ~IFileSystem( void );

		DECL_IOBJECT_INTERFACE( IFileSystem , IObject );

	public:

	//@ interface

		/*!
			\brief		Query file exists.
		*/
		virtual bool FileExist( const WString& path ) = 0;

		/*!
			\brief		Query directory exists.
		*/
		virtual bool DirectoryExist( const WString& path ) = 0;

		/*!
			\brief		Get specific file info.
		*/
		virtual bool GetFileInfo( const WString& path , DataInfo& info ) = 0;

		/*!
			\brief		Create directory at specific location.
		*/
		virtual bool CreateDirectory( const WString& path ) = 0;

		/*!
			\brief		Create file at specific location.
		*/
		virtual RefPass<IFile> CreateFile( const WString& path ) = 0;

		/*!
			\brief		Open file at specific location.
		*/
		virtual RefPass<IFile> OpenFile( const WString& path ) = 0;

		/*!
			\brief		Open POSIX type file handle.
		*/
		virtual FILE * OpenPosixFile( const char * path , const char * mode ) = 0;

		/*! 
			\brief		Open IStream instance of file system (read-only).
		*/
		virtual IStream * OpenIStream( const WString& path ) = 0;

		/*!
			\brief		Copy a file to specific location.
		*/
		virtual bool CopyFile( const WString& src , const WString& dst ) = 0;

		/*!
			\brief		Delete a file from a specific location.
		*/
		virtual bool DeleteFile( const WString& path ) = 0;

		/*!
			\brief		List a directory.
		*/
		virtual bool ListDir( const WString& path , const WString& spec , std::vector<WString>& files ) = 0;

		struct IEnumFileData
		{
			DataType		type;
			DataInfo		info;
			const wchar_t *	name;
		};

		/*!
			\brief		Enumerate files in a directory.
		*/
		virtual void EnumerateFiles( const WString& path , const WString& spec ,
			function<void(const IEnumFileData&)> handler ) = 0;

		/*!
			\brief		Create corresponding data entry from file.
		*/
		virtual RefPass<IData> CreateEntryFromFile( const WString& path ) = 0;

		/*!
			\brief		Load exist entry from file.
		*/
		virtual RefPass<IData> LoadEntryFromFile( const WString& path ) = 0;
	};

} // namespace xeres
